<?php

namespace App\Console\Commands\Shop;

use App\Kuafu\Shop\Model\Shop;
use Illuminate\Console\Command;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\Artisan;

class SyncNewShopRecord extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'shop:sync_new_shop_record';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = '门店档案增量同步';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return int
     */
    public function handle()
    {
        // 获得新增的门店数据
        $shopIds = Shop::query()
            ->whereBetween('createdAt', [Carbon::now()->subDay()->startOfDay()->timestamp, Carbon::now()->subDay()->endOfDay()->timestamp])
            ->pluck('id')
            ->toArray();

        if (count($shopIds)) {
            Artisan::call('shop:init_shop_and_shop_staff_records --shopIds=' . join(',',$shopIds));
        }
    }
}
